(function(global){
	global.TRCKR = global.TRCKR || {};

    var activeDomain = null;
    global.TRCKR.trackerModel = function(){
        var addEntry = function(domain){
            var domains = getAll();
            if(!domains.hasOwnProperty(domain)) { //adding new domain
                domains[domain] = {
                    totalTime: 0,
                    lastVisit: 0
                };
            }
            if(activeDomain) {
                domains[activeDomain].totalTime += (+ new Date()) - domains[activeDomain].lastVisit;
            }
            activeDomain = domain;
            domains[domain].lastVisit = + new Date();
            localStorage.setItem("TRCKR.domains", JSON.stringify(domains));
        };
        var getAll = function(){
            return JSON.parse(localStorage.getItem("TRCKR.domains") || "{}");
        };

    	return {
            addEntry: addEntry,
            getAll: getAll
        };
    };
})(this);